﻿using FluentValidation;
using Grundy.Common;

namespace Grundy.Message
{
    public class ContainerValidator : AbstractValidator<Container>
    {
        public ContainerValidator()
        {
            this.CascadeMode = CascadeMode.Continue;
            RuleFor(c => c.Signee).Must((c, cs) => cs != ContainerSigneeType.None).WithMessage("Cannot verify containers signed by this signee.");
            RuleFor(c => c.Signee).Must((c, cs) =>
                                            {
                                                if (cs == ContainerSigneeType.EntitlementServer || cs == ContainerSigneeType.Server)
                                                    return c.Provider.EqualsIgnoreCase("RsaProvider");
                                                return c.Provider.Contains("Sha256MacProvider");
                                            }).WithMessage("Incorrect provider string.");
            RuleFor(c => c.Signature).NotEmpty().WithMessage("Signature is mandatory for container to be verified.");
            RuleFor(c => c.Payload).NotEmpty().WithMessage("Payload is mandatory for container to be verified.");
        }

    }
}